package com.fsoft.core.icon.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fsoft.core.Global;
import com.fsoft.core.common.base.service.impl.BaseServiceImpl;
import com.fsoft.core.icon.entity.SysIcon;
import com.fsoft.core.icon.mapper.SysIconMapper;
import com.fsoft.core.icon.service.IconService;
import com.fsoft.core.utils.DateTimeUtils;
import com.fsoft.core.utils.OgnlUtils;

/**
 * F-Soft
 * @package com.fsoft.core.icon.service.impl
 * @author Fish
 * @email it.fish2010@foxmail.com
 * @date 2020-02-17
 * @CopyRight © F-Soft
 **/
@Service
@Transactional
public class IconServiceImpl extends BaseServiceImpl<SysIcon> implements IconService {

	@Autowired
	private SysIconMapper iconMapper;

	@Override
	public SysIcon getEntity(String rwid) throws Exception {
		return iconMapper.selectByKey(rwid);
	}

	@Override
	public int save(SysIcon entity) throws Exception {
		if (OgnlUtils.isEmpty(entity.getSortNo()))
			entity.setSortNo(BigDecimal.ONE);
		if (OgnlUtils.isEmpty(entity.getStatus()))
			entity.setStatus(Global.STATUS_YES);
		return super.save(entity);
	}

	@Override
	public int modify(SysIcon entity) throws Exception {
		if (OgnlUtils.isEmpty(entity.getModifyTime()))
			entity.setModifyTime(DateTimeUtils.getNowTime());
		return super.modify(entity);
	}

	@Override
	public int removeBatch(List<String> ids) throws Exception {
		if (OgnlUtils.isEmpty(ids))
			return 0;
		if (ids.size() == 1)
			return remove(ids.get(0));
		return super.removeBatch(ids);
	}
}
